#
# Run experiments for diploma thesis (new, DPM kernels).
#

use strict;
use warnings;

my $home = 'C:\Users\ungerma\Desktop\DA\dual-process-model\dpm';
my $run = "$home\\dist\\Debug\\MinGW-Windows\\dpm.exe ";
my $additional = '-# 3000 -m 512';

sub printRun {
  my $cmd = shift;
  print "$cmd\n";
  return system($cmd);
}

printRun($run . 'features') == 0 or die('Could not run cmd');
for my $mode (2, ) {
  for my $gf ( 2,1,0,4,5,) { # generalization 
    for my $lhs ( 0, 1,3,4,5,6,8,9,10,11,12,15,16,17,20..35,37..51,53,54,55..71,72,73,74,) { # similarity, ie. a/x or x/-a # 
	  for my $rhs ( 2, 7,13,14,18,19,36,52,53,54,71,72,) { # distance, ie. b/x or c/x # 
		
		next if $gf == 2 && $lhs == 0 && $rhs == 7;
		next if $gf == 2 && $lhs == 0 && $rhs == 13;
		next if $gf == 2 && $lhs == 0 && $rhs == 18;
		next if $gf == 2 && $lhs == 0 && $rhs == 19;
		next if $gf == 2 && $lhs == 0 && $rhs == 36;
		next if $gf == 2 && $lhs == 0 && $rhs == 52;
		next if $gf == 4 && $lhs == 0 && $rhs == 36;
		next if $gf == 4 && $lhs == 0 && $rhs == 52;		
		next if $lhs == 6 && $rhs == 2;
		next if $lhs == 9 && $rhs == 53;
		next if $lhs == 31 && $rhs == 54;
		next if $lhs == 32 && $rhs == 2;
		next if $lhs == 42 && $rhs == 14;
		next if $lhs == 42 && $rhs == 53;
		next if $lhs == 42 && $rhs == 54;
		next if $lhs == 42 && $rhs == 71;
		next if $lhs == 43 && $rhs == 14;
		next if $lhs == 43 && $rhs == 71;
		next if $lhs == 46 && $rhs == 2;
		next if $lhs == 48 && $rhs == 36;
		next if $lhs == 48 && $rhs == 52;
		next if $lhs == 71 && $rhs == 36;
		next if $lhs == 71 && $rhs == 52;
		next if $rhs == 7;
        next if $rhs == 9;
        next if $lhs == 10;
        next if $lhs == 12;
		next if $rhs == 53;
		next if $rhs == 54;
		next if $rhs == 71;
		next if $rhs == 72;
		
	    next if printRun($run . "train \"-t 4 -g $gf -s $lhs -d $rhs -r $mode $additional\"");
		next if printRun($run . 'classify');
		opendir D, "$home\\gen" or die "Could not open dir: $!\n";
		my @files = grep(/pr\d+/i, readdir D);
		closedir D;
		if(scalar @files == 1) {
			my $file = $files[0];
			$file =~ /(\d+)/;
			my $score = $1;
			printRun("move $home\\gen\\$file $home\\gen\\pr-${score}-${mode}-${gf}-${lhs}-${rhs}.txt");
		}
		else {
			die("Did not find exactly one proper result file.");
		}
	  }
	}
  }
}
